//----------------------------------------------------------------------------
// util.h
//
// utility functions for nclip
//
// Copyright (C) 2010 Neil Butterworth
//----------------------------------------------------------------------------

#ifndef INC_NCLIP_UTIL_H
#define INC_NCLIP_UTIL_H

#include <windows.h>
#include <sstream>
#include <string>
#include <climits>
#include <vector>

//----------------------------------------------------------------------------
// Helper to convert any type to string a la Boost lexical_cast.
//----------------------------------------------------------------------------

template <typename T>
std::string Str( const T & t ) {
	std::ostringstream os;
	os << t;
	return os.str();
}

//----------------------------------------------------------------------------
// Functions
//----------------------------------------------------------------------------

std::string LastWinError();
std::string GetTextData();
std::vector<std::string> GetDropFiles();
bool HasFormat( UINT cf );
bool HasFormat( const std::string &  cf );
void SetTextData( const std::string & s, bool append );
bool ToInteger( const std::string & s, long & n );
bool IsInteger( const std::string & s );
bool KnownFormat( UINT cf );
std::string CFToStr( UINT cf );

//----------------------------------------------------------------------------
// Simple RAII class to make sure clipboard gets closed no matter what.
//----------------------------------------------------------------------------

class Clipboard {

	public:

		Clipboard() {
			if ( ! ::OpenClipboard( NULL ) ) {
				throw ClipError( LastWinError() );
			}
		}

		~Clipboard() {
			::CloseClipboard();
		}
};
#endif

